
(function(ns){

var Asset = ns.Asset = Hilo.Class.create({
    Mixes: Hilo.EventMixin,

    queue: null,
    bg: null,
	yun1: null,
	yun2: null,
	hu: null,
	bighu:null,
	newnum: null,
    ground: null,
    ready: null,
    over: null,
	
    numberGlyphs: null,
    birdAtlas: null,
	yunAtlas: null,
	huAtlas: null,
	waterAtlas:null,
	zhongziAtlas:null,
	ycallAtlas:null,
	txiconAtlas:null,
	miaoiconAtlas:null,
	bigguaAtlas:null,
	smallguaAtlas:null,
	jsiconAtlas:null,
	
	
    holdback: null,
	righttar: null,
	kuan:null,
	tiao:null,
	water:null,
	zhongzi:null,
	waiground:null,
	neiground:null,
	neijia:null,
	niba:null,
	shou:null,
	tiaoback: null,
	ycall: null,
	txicon: null,
	biggua: null,
	smallgua: null,
	miaoicon:null,
	jsicon:null,
	myxigua:null,
	gamerule:null,
	box:null,
	bigbox:null,
	btn1:null,
	btn2:null,
	cha:null,
	TotalNum:0,
    load: function(){
        var resources = [
            {id:'bg', noCache:false, src:'images/fambackIcon.png'},
            // {id:'ground', src:'images/ground.png'},
            // {id:'ready', src:'images/ready.png'},
            // {id:'over', src:'images/over.png'},
			{id:'newnum', noCache:true,  src:'images/newnum.png'},
			{id:'yun1', noCache:false,  src:'images/yun1.png'},
			{id:'yun2', noCache:false,  src:'images/yun2.png'},
			{id:'hu', noCache:false, src:'images/hu.png'},
			{id:'bighu', noCache:false, src:'images/bighu.png'},
			{id:'righttar', noCache:false, src:'images/righttar.png'},
			{id:'kuan',noCache:false, src:'images/kuan.png'},
			// {id:'water',noCache:false, src:'images/fish.png'},
			// {id:'mygua', src:'images/mygua.png'},
			// {id:'rule', src:'images/rule.png'},
			{id:'zhongzi',noCache:false, src:'images/zhongzi.png'},
			{id:'waiground',noCache:false, src:'images/waiground.png'},
			{id:'neiground',noCache:false, src:'images/neiground.png'},
			{id:'neijia',noCache:false, src:'images/neijia.png'},
			{id:'niba',noCache:false, src:'images/niba.png'},
			{id:'shou',noCache:false, src:'images/shou.png'},
			{id:'tiaoback',noCache:false, src:'images/tiaoback.png'},
			{id:'ycall',noCache:false, src:'images/ycall.png'},
			{id:'txicon',noCache:false, src:'images/txicon.png'},
			{id:'miaoicon',noCache:false, src:'images/miaoicon.png'},
			{id:'biggua',noCache:false, src:'images/biggua.png'},
			{id:'smallgua',noCache:false, src:'images/smallgua.png'},
			{id:'jsicon',noCache:false, src:'images/jsicon.png'},
			{id:'myxigua',noCache:false, src:'images/myxigua.png'},
			{id:'gamerule',noCache:false, src:'images/gamerule.png'},
			//弹窗
			{id:'box',noCache:false, src:'images/box.png'},
			{id:'bigbox',noCache:false, src:'images/bigbox.png'},
			{id:'btn1',noCache:false, src:'images/btn1.png'},
			{id:'btn2',noCache:false, src:'images/btn2.png'},
			{id:'cha',noCache:false, src:'images/cha.png'},
			
			// {id:'miao', src:'images/miao.png'},
			{id:'tiao',noCache:false, src:'images/tiao.png'}
            // {id:'bird', src:'images/bird.png'},
            // {id:'holdback', src:'images/holdback.png'}
        ];

        this.queue = new Hilo.LoadQueue();
        this.queue.add(resources);
		//console.log(this.queue)
		this.queue.on('load', this.onLoad.bind(this));
        this.queue.on('complete', this.onComplete.bind(this));
        this.queue.start();
    },
	onLoad: function(e){
		this.TotalNum++
		$("#loadtext").attr("data-text", "西瓜农场正在加载... " + (this.TotalNum/this.queue.getTotal() * 100 | 0) + "%");
		//console.log(this.TotalNum/this.queue.getTotal())
	},
    onComplete: function(e){
        this.bg = this.queue.get('bg').content;
		this.yun1 = this.queue.get('yun1').content;
		this.yun2 = this.queue.get('yun2').content;
		this.hu = this.queue.get('hu').content;
		this.bighu = this.queue.get('bighu').content;
		this.newnum = this.queue.get('newnum').content;
		this.righttar = this.queue.get('righttar').content;
		this.kuan = this.queue.get('kuan').content;
		this.tiao = this.queue.get('tiao').content;
		// this.water = this.queue.get('water').content;
		this.zhongzi = this.queue.get('zhongzi').content;
		this.waiground = this.queue.get('waiground').content;
		this.neiground = this.queue.get('neiground').content;
		this.neijia = this.queue.get('neijia').content;
		this.niba = this.queue.get('niba').content;
		this.shou = this.queue.get('shou').content;
		this.tiaoback = this.queue.get('tiaoback').content;
		this.ycall = this.queue.get('ycall').content;
		this.txicon = this.queue.get('txicon').content;
		this.miaoicon = this.queue.get('miaoicon').content;
		this.biggua = this.queue.get('biggua').content;
		this.smallgua = this.queue.get('smallgua').content;
		this.jsicon = this.queue.get('jsicon').content;
		this.myxigua = this.queue.get('myxigua').content;
		this.gamerule = this.queue.get('gamerule').content;
		this.box = this.queue.get('box').content;
		this.bigbox = this.queue.get('bigbox').content;
		this.btn1 = this.queue.get('btn1').content;
		this.btn2 = this.queue.get('btn2').content;
		this.cha = this.queue.get('cha').content;
		
		this.yunAtlas1 = new Hilo.TextureAtlas({
		    image: this.queue.get('yun1').content,
		    frames: [[0, 0, 132, 56]],
		    sprites: {yun: [0]}
		});
		this.yunAtlas2 = new Hilo.TextureAtlas({
		    image: this.queue.get('yun2').content,
		    frames: [[0, 0, 106, 56]],
		    sprites: {yun: [0]}
		});
		
		this.huAtlas = new Hilo.TextureAtlas({
		    image: this.queue.get('hu').content,
		    frames: [[0, 0, 102, 114]],
		    sprites: {hu: [0]}
		});
		
		this.zhongziAtlas = new Hilo.TextureAtlas({
		    image: this.queue.get('zhongzi').content,
			width: 1020,
			height: 60,
			frames: {
		       frameWidth: 60,
		       frameHeight: 60,
		       numFrames: 17
			},
			sprites: {
				zhongzi: {from:0, to:16}
			}
		});
		
		// this.waterAtlas = new Hilo.TextureAtlas({
		//     image: this.queue.get('water').content,
		// 	frames: {
		//        frameWidth: 174,
		//        frameHeight: 126,
		//        numFrames: 12
		// 	},
		// 	sprites: {
		// 		water: {from:0, to:11}
		// 	}
		// });
		
		this.ycallAtlas = new Hilo.TextureAtlas({
		    image: this.queue.get('ycall').content,
			width: 7100,
			height: 240,
			frames: {
		       frameWidth: 100,
		       frameHeight: 240,
		       numFrames: 71
			},
			sprites: {
				ycall: {from:0, to:70}
			}
		});
		
		this.txiconAtlas = new Hilo.TextureAtlas({
		    image: this.queue.get('txicon').content,
			width: 1500,
			height: 120,
			frames: {
		       frameWidth: 100,
		       frameHeight: 120,
		       numFrames: 15
			},
			sprites: {
				txicon: {from:0, to:14}
			}
		});
		
		this.miaoiconAtlas = new Hilo.TextureAtlas({
		    image: this.queue.get('miaoicon').content,
			width: 11200,
			height: 120,
			frames: {
		       frameWidth: 160,
		       frameHeight: 120,
		       numFrames: 70
			},
			sprites: {
				miaoicon: {from:0, to:69}
			}
		});
		this.bigguaAtlas = new Hilo.TextureAtlas({
		    image: this.queue.get('biggua').content,
			width: 12000,
			height: 150,
			frames: {
		       frameWidth: 200,
		       frameHeight: 150,
		       numFrames: 60
			},
			sprites: {
				biggua: {from:0, to:59}
			}
		});
		this.smallguaAtlas = new Hilo.TextureAtlas({
		    image: this.queue.get('smallgua').content,
			width: 8400,
			height: 120,
			frames: {
		       frameWidth: 120,
		       frameHeight: 120,
		       numFrames: 70
			},
			sprites: {
				smallgua: {from:0, to:69}
			}
		});
		this.jsiconAtlas = new Hilo.TextureAtlas({
		    image: this.queue.get('jsicon').content,
			width: 5600,
			height: 180,
			frames: {
		       frameWidth: 160,
		       frameHeight: 180,
		       numFrames: 35
			},
			sprites: {
				jsicon: {from:0, to:34}
			}
		});
		
		

        // var number = this.queue.get('number').content;
        // this.numberGlyphs = {
        //     0: {image:number, rect:[0,0,30,91]},
        //     1: {image:number, rect:[30,0,30,91]},
        //     2: {image:number, rect:[60,0,30,91]},
        //     3: {image:number, rect:[120,0,30,91]},
        //     4: {image:number, rect:[150,0,30,91]},
        //     5: {image:number, rect:[180,0,30,91]},
        //     6: {image:number, rect:[210,0,30,91]},
        //     7: {image:number, rect:[240,0,30,91]},
        //     8: {image:number, rect:[270,0,30,91]},
        //     9: {image:number, rect:[300,0,30,91]}
        // };

        this.queue.off('complete');
        this.fire('complete');
		$("#container").hide();
    }
});

})(window.game);